﻿using System.Linq;
using System.Collections.Generic;

namespace Inovout.Gis.Land.XZQMap
{
    public class XZQPolygonLayer : HightLowLayer<XZQ>
    {
        #region Constructor

        public XZQPolygonLayer(IGisTable gisTable)
            : base(gisTable)
        {
        }


        #endregion

        internal static string[] TableNames = new string[] { "G11_H_PY", "G12_H_PY", "G13_H_PY" }; 

        protected IEnumerable<XZQPolygonLayer> XZQPolygonLayers
        {
            get { return MapObject.Current.AllLayers.Where(layer => layer is XZQPolygonLayer).Cast<XZQPolygonLayer>(); }
        }

        private List<XZQPolygonLayer> children = new List<XZQPolygonLayer>();
        public IEnumerable<XZQPolygonLayer> Children
        {
            get { return children; }
        }
        public XZQPolygonLayer TopLayer { get; set; }
        public int Level { get; set; }
        private XZQPolygonLayer lowXZQLayer;
        public XZQPolygonLayer LowXZQLayer
        {
            get
            {
                if (lowXZQLayer == null)
                {
                    KeyValuePair<int, string> lowXZQLayerDescriptor = Map.GrainedLayerDescriptors.First(descriptor=>descriptor.Key>Level);
                    lowXZQLayer = Map.Layers.Single(layer => layer.Name.Equals(lowXZQLayerDescriptor.Value)) as XZQPolygonLayer;
                    lowXZQLayer.Map = Map;
                    lowXZQLayer.TopLayer = this;
                    lowXZQLayer.Level = lowXZQLayerDescriptor.Key;
       
                }
                return lowXZQLayer;
            }
        }

        public new XZQMap Map
        {
            get { return base.Map as XZQMap; }
            internal set { base.Map = value; }
        }
    }
}
